3D激光slam 您所在的位置:网站首页 pcl 打印 3D激光slam

3D激光slam

#3D激光slam| 来源: 网络整理| 查看: 265

点云数据格式定义

首先要定义自己的点云数据类型,用来存储点云。

首先定义一个点的数据类型:

template struct Point3_ { using ValueType = T; Point3_() { } ~Point3_() { } Point3_( const T& x_, const T& y_, const T& z_ ) : x( x_ ), y( y_ ), z( z_ ) { } T x = 0; T y = 0; T z = 0; };

很简单,只有三个变量,用来表示点在空间中的位置即可。

而点云则是所有点的集合,这里可以用vector来动态存储,更加方便。

template struct PointCloud_ { using PointType = T; using Ptr = std::unique_ptr; PointCloud_() { } PointCloud_( const uint64_t& time_stamp_, const int& width_, const int& height_ ) : time_stamp( time_stamp_ ), width( width_ ), height( height_ ) { points.resize( width * height ); } uint64_t time_stamp = -1; int width = 0; int height = 0; //T* points = nullptr; std::vector points; };

这里增添了时间戳变量,并与pcl里面保持一致,增加了width和height变量用来表示点云的大小。

2. 点云数据类型转换以及存储

由于我们使用的KITTI的数据集的数据,一般网上可以直接下载到对应的rosbag。由于ros中使用的数据类型为sensor_msgs::pointcloud2,与我们上述的数据类型不一样,因此需要进行转换。同时为了后续使用,还需要对数据进行存储。

因此这里我们要在ros环境下将rosbag转成我们自己的数据存储格式。转化用的ros package可见于仓库:

代码逻辑分析如下:

首先订阅数据集rosbag中雷达数据的topic,然后以二进制格式创建一个新的文件,文件名和后缀可以随便取。

int main( int argc, char **argv ) { ros::init( argc, argv, "ReadData" ); ros::NodeHandle n; ros::Subscriber scan_sub = n.subscribe("/velodyne_points", 1, laserCallback); // ---------- open the file --------------// outfile.open( "./kitti_small_loam", std::ios::app ); if( !outfile.is_open() ){ std::cerr


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

      专题文章
        CopyRight 2018-2019 实验室设备网 版权所有